package middleware

import (
	"github.com/gin-gonic/gin"
	"task_queue/global"
	"task_queue/internal/models"
)

// RequestIDMiddleware 为每个请求生成一个唯一的 request ID
func AuthMiddleware() gin.HandlerFunc {
	return func(c *gin.Context) {
		key := c.Param("key")
		var authKey models.AuthKey
		if err := global.GlobalP.DB.Model(&authKey).Where("auth_key_value = ?", key).First(&authKey).Error; err == nil {
			c.Redirect(302, "/auth/not_found")
			return
		}
		c.Set("key", key)

		c.Next()
	}
}
